package main

import (
	"flag"
	"fmt"
	"iot-base/common/eventtype"
	"iot-base/common/notify"
	"strconv"
	"time"
)

var id string
var aid string
var aindex string
var aflag string
var atype string

func ReportAlarm(tid string, aid string, index int64, flag string) {
	var curAlarm eventtype.Alarm
	curAlarm.TID = tid
	curAlarm.AlarmID = aid
	curAlarm.Mindex = index

	curAlarm.Flag = flag
	curAlarm.Time = time.Now().Unix()
	notify.RawAlarm(&curAlarm)
}

func ReportEvent(tid string) {
	fmt.Println("上报事件")
	notify.RawEvent(tid, "test", time.Now(), nil, nil)
}
func init() {
	flag.StringVar(&id, "id", "default", "log in user")
	flag.StringVar(&aid, "aid", "default", "log in user")
	flag.StringVar(&aindex, "aindex", "0", "log in user")
	flag.StringVar(&aflag, "aflag", "BEGIN", "log in user")
	flag.StringVar(&atype, "atype", "0", "")
}
func main() {
	println(id, aid, aindex)
	flag.Parse() //暂停获取参数
	if atype == "0" {
		// 告警
		index, _ := strconv.ParseInt(aindex, 10, 64)
		ReportAlarm(id, aid, index, aflag)
	} else {
		// 事件
		ReportEvent(id)
	}
}
